package com.infrastructure.net;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by zyt on 16/6/14 11:37 .
 * Email : syy19930112@aliyun.com
 * Description:
 * <p>
 * 封装网络请求的参数.
 * </p>
 */
public class RequestParameter implements Comparable<Object>, Parcelable {
    private String name;

    private String value;

    public RequestParameter(final String name, final String value) {
        this.name = name;
        this.value = value;
    }

    @Override
    public int compareTo(Object another) {
        int compared;
        /**
         * 值比较
         */
        final RequestParameter parameter = (RequestParameter) another;
        compared = name.compareTo(parameter.name);
        if (compared == 0) {
            compared = value.compareTo(parameter.value);
        }
        return compared;
    }

    @Override
    public boolean equals(Object o) {
        if (null == o) {
            return false;
        }

        if (this == o) {
            return true;
        }

        if (o instanceof RequestParameter) {
            final RequestParameter parameter = (RequestParameter) o;
            return name.equals(parameter.name) && value.equals(parameter.value);
        }

        return false;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.name);
        dest.writeString(this.value);
    }

    protected RequestParameter(Parcel in) {
        this.name = in.readString();
        this.value = in.readString();
    }

    public static final Parcelable.Creator<RequestParameter> CREATOR = new Parcelable.Creator<RequestParameter>() {
        @Override
        public RequestParameter createFromParcel(Parcel source) {
            return new RequestParameter(source);
        }

        @Override
        public RequestParameter[] newArray(int size) {
            return new RequestParameter[size];
        }
    };
}
